package cn.net.qinling.healthcare.test.datagen;

import java.util.List;
import java.util.Random;

import cn.net.qinling.healthcare.test.datagen.PersonGenerator.PersonInfo;

public class PersonGenerator extends Generator<PersonInfo> {
	
	public class PersonInfo {
		private String firstName;
		
		private String lastName;
		
		private String gender;
		
		private String id;
		
		private String dob;

		public String getFirstName() {
			return firstName;
		}

		public void setFirstName(String firstName) {
			this.firstName = firstName;
		}

		public String getLastName() {
			return lastName;
		}

		public void setLastName(String lastName) {
			this.lastName = lastName;
		}

		public String getGender() {
			return gender;
		}

		public void setGender(String gender) {
			this.gender = gender;
		}

		public String getId() {
			return id;
		}

		public void setId(String id) {
			this.id = id;
		}

		public String getDob() {
			return dob;
		}

		public void setDob(String dob) {
			this.dob = dob;
		}
	}

	public PersonGenerator(Selector selector) {
		super(selector);
	}

	public static void main(String[] args) {
		Selector selector = ExcelFileSelector.getSelector("e:\\codes.xls");
		PersonGenerator pg = new PersonGenerator(selector);
		for (int i = 0; i < 100; i++) {
			pg.generate();
		}
	}

	@Override
	protected PersonInfo doGeneration() {
		List<String> fnValues = selector.next("FamilyName");
		List<String> gnValues = selector.next("GivenName");
		String lastName = fnValues.get(0);
		String firstName = gnValues.get(0);
		String gender = gnValues.get(2);

		String birthString = TimeUtil.getRandomTime("yyyyMMdd");
		
		List<String> selectedCityInfo = selector.next("city");
		String idPrefix = selectedCityInfo.get(3);
		String idSurfix = Integer.toString(new Random().nextInt(8999) + 1000);
		String id = idPrefix + birthString + idSurfix;
		
		//System.out.println(id + " " + lastName + firstName + "(" + gender + ")" + " - " + birthString);
		PersonInfo info = new PersonInfo();
		info.setFirstName(firstName);
		info.setLastName(lastName);
		info.setGender(gender);
		info.setDob(birthString);
		info.setId(id);
		
		return info;
	}
	
	

}
